<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title></title>
<link rel="stylesheet" href="${staticServer}/inc/style/main.css" />
<link rel="stylesheet" href="${staticServer}/inc/style/page.css" />
<link rel="stylesheet" href="${staticServer}/css/struct_info.css" />
<link rel="stylesheet" href="${staticServer}/inc/style/date/datepicker.css" />

<script src="${staticServer}/inc/js/jquery.js"></script>
<script src="${staticServer}/inc/js/datepicker.js"></script>
<script src="${staticServer}/inc/js/pageset.js"></script>
<script src="${staticServer}/inc/js/submitter.js"></script>
<script>
var contextPath='${contextPath}';
$(function(){
	$("#grade").val('${workload.grade}');
	$("#month").val('${workload.month}');
	querys_grade('${workload.grade}');
	
	$("#form_submit").click(function(){
		var data = {};
		data.ids = $("#ids").val();
		data.grade = $("#grade").val();
		data.cdate = $("#cdate").val();
		data.money = $("#money").val();
		data.reception = $("#reception").val();
		data.reserve = $("#reserve").val();
		data.track = $("#track").val();
		
		if(data.grade==""){
			alert("区域等级不能为空！");
			return false;
		}
		if(data.cdate==""){
			alert("年月时间不能为空！");
			return false;
		}
		if(data.money==""){
			alert("业绩任务量不能为空！");
			return false;
		}
		
		if(data.reception==""){
			alert("接待率任务量不能为空！");
			return false;
		}
		
		if(data.reserve==""){
			alert("邀约实际到访率任务量不能为空！");
			return false;
		}
		
		if(data.track==""){
			alert("每月电话任务量不能为空！");
			return false;
		}
		
		var regions = [];
		$( "#region" ).find( "input:checkbox" ).each( function( id ){
		if( $( this ).prop( "checked" ) )
			regions.push( $( this ).attr( "id" ) );
		} );
		data.regions = regions.join( "," );
		submitter.post( "${contextPath}/index/add_work_load.json", data, function( d ){
			alert("保存成功！");
			}, "json" );
		
	});
})

function querys_grade(id){
	var region = "";
	$("[name=items]:checkbox").prop("checked", false);
	if(id=="1"){
		region = "one";
	}else if(id=="2"){
		region = "two";
	}else if(id=="3"){
		region = "three";
	}
	if(region!=null && region!=""){
		$("."+region).prop('checked',true);
	}
	querys_repeat(id,'');
}

$( "body" ).ready( function( e ){
		select_date( 'cdate', dateSelected );
	});
	
	function select_date( targetid, func ){
	$( '#' + targetid ).Zebra_DatePicker( { format: 'Y-m', show_icon: false, onSelect: func } );
}

function dateSelected(date){
	var id = "";
	querys_repeat(id,date);
}

function querys_repeat(id,date){
	var data = {};
		
		if(id!=null && id!=""){
			data.id = id;
		}else{
			data.id = $("#grade").val();
		}
		if(date!=null && date!=""){
			data.cdate = date;
		}else{
			data.cdate = $("#cdate").val();
		}
		if(data.cdate!="" && data.id!=""){
		$.post( "${contextPath}/index/query_repeat.json", data, function( d ){
		var work = d.workload;
		if(work!=null && work!=""){
			$("#money").attr('value',work.total_money);
			$("#reception").attr('value',work.reception);
			$("#reserve").attr('value',work.reserve);
			$("#track").attr('value',work.track);
			$("#ids").attr('value',work.id);
		  }else{
		  	$("#money").attr('value','');
			$("#reception").attr('value','');
			$("#reserve").attr('value','');
			$("#track").attr('value','');
			$("#ids").attr('value','');
		 }
		}, "json" );
	 }else{
		  	$("#money").removeAttr('value');
			$("#reception").removeAttr('value');
			$("#reserve").removeAttr('value');
			$("#track").removeAttr('value');
			$("#ids").attr('value','');
		 }
}

</script>
</head>

<body>
	<input type="hidden" id="ids" value="${workload.id}">
	<div id="container">
		<div id="title"></div>
		<table id="infotable">
			<tr>
				<th width="25%">区域等级划分</th>
				<td width="75%">
					<select id="grade" onchange="querys_grade(this.value)">
							<option value="">请选择区域等级</option>
							<option value="1">一级区域</option>
							<option value="2">二级区域</option>
							<option value="3">三级区域</option>
					</select>				
				</td>
			</tr>
			<tr>
				<th>地区选择</th>
				<td id="source">
					<ul id="region">
						<li class="unit" style="list-style:none;float:left;width:100px;margin:2px;">
							<input type="checkbox" name="items" class="one" id="北京" ><label>北京</label>
						</li>
						<li class="unit" style="list-style:none;float:left;width:100px;margin:2px;">
							<input type="checkbox" name="items" class="one" id="上海"><label>上海</label>
						</li>
						<li class="unit" style="list-style:none;float:left;width:100px;margin:2px;">
							<input type="checkbox" name="items" class="one" id="天津"><label>天津</label>
						</li>
						<li class="unit" style="list-style:none;float:left;width:100px;margin:2px;">
							<input type="checkbox" name="items" class="two" id="广州" ><label>广州</label>
						</li>
						<li class="unit" style="list-style:none;float:left;width:100px;margin:2px;">
							<input type="checkbox" name="items" class="two" id="深圳"><label>深圳</label>
						</li>
						<li class="unit" style="list-style:none;float:left;width:100px;margin:2px;">
							<input type="checkbox" name="items" class="two" id="杭州"><label>杭州</label>
						</li>
						<li class="unit" style="list-style:none;float:left;width:100px;margin:2px;">
							<input type="checkbox" name="items" class="two" id="南京" ><label>南京</label>
						</li>
						<li class="unit" style="list-style:none;float:left;width:100px;margin:2px;">
							<input type="checkbox" name="items" class="two" id="武汉"><label>武汉</label>
						</li>
						<li class="unit" style="list-style:none;float:left;width:100px;margin:2px;">
							<input type="checkbox" name="items" class="three" id="无锡"><label>无锡</label>
						</li>
						<li class="unit" style="list-style:none;float:left;width:100px;margin:2px;">
							<input type="checkbox" name="items" class="three" id="苏州" ><label>苏州</label>
						</li>
						<li class="unit" style="list-style:none;float:left;width:100px;margin:2px;">
							<input type="checkbox" name="items" class="two" id="宁波"><label>宁波</label>
						</li>
						<li class="unit" style="list-style:none;float:left;width:100px;margin:2px;">
							<input type="checkbox" name="items" class="three" id="重庆"><label>重庆</label>
						</li>
						<li class="unit" style="list-style:none;float:left;width:100px;margin:2px;">
							<input type="checkbox" name="items" class="three" id="成都" ><label>成都</label>
						</li>
						<li class="unit" style="list-style:none;float:left;width:100px;margin:2px;">
							<input type="checkbox" name="items" class="three" id="长沙"><label>长沙</label>
						</li>
						<li class="unit" style="list-style:none;float:left;width:100px;margin:2px;">
							<input type="checkbox" name="items" class="three" id="沈阳"><label>沈阳</label>
						</li>
						<li class="unit" style="list-style:none;float:left;width:100px;margin:2px;">
							<input type="checkbox" name="items" class="three" id="东莞"><label>东莞</label>
						</li>
						<li class="unit" style="list-style:none;float:left;width:100px;margin:2px;">
							<input type="checkbox" name="items" class="three" id="佛山"><label>佛山</label>
						</li>
					</ul>
				</td>
			</tr>
			<tr>
			<th width="25%">年月时间</th>
				<td width="75%">
					<input type="text" name="cdate" id="cdate" size="15" value="${date}" rel="DATE::Y-m" />
				</td>
			</tr>
			<tr>
				<th>业绩目标量</th>
				<td><input id="money" type="money" size="20" value="${workload.total_money}" maxlength="30" /> 万</td>
			</tr>
			<tr>
				<th>接待成交率目标量</th>
				<td><input id="reception" type="money" size="20" value="${workload.reception}" maxlength="30" /> %</td>
			</tr>
			<tr>
				<th>邀约到访目标量</th>
				<td><input id="reserve" type="money" size="20" value="${workload.reserve}" maxlength="30" /> 个</td>
			</tr>
			<tr>
				<th>每月电话目标量</th>
				<td><input id="track" type="money" size="20" value="${workload.track}" maxlength="30" /> 个</td>
			</tr>
		</table>
		<div id="controlbar">
			<input type="button" class="submit" id="form_submit" value=" 保存  " />
		</div>
	</div>
</body>
</html>